package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResPackage;
import com.ruoyi.system.service.IResPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆套餐Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/system/respackage")
public class ResPackageController extends BaseController
{
    @Autowired
    private IResPackageService resPackageService;

    /**
     * 查询餐馆套餐列表
     */
//    @PreAuthorize("@ss.hasPermi('system:respackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResPackage resPackage)
    {
        startPage();
        List<ResPackage> list = resPackageService.selectResPackageList(resPackage);
        System.out.println(list);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:respackage:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(ResPackage resPackage, Long userId)
    {
        startPage();
        List<ResPackage> list = resPackageService.selectResPackageListByUserId(resPackage, userId);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出餐馆套餐列表
     */
    @PreAuthorize("@ss.hasPermi('system:respackage:export')")
    @Log(title = "餐馆套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResPackage resPackage)
    {
        List<ResPackage> list = resPackageService.selectResPackageList(resPackage);
        ExcelUtil<ResPackage> util = new ExcelUtil<ResPackage>(ResPackage.class);
        util.exportExcel(response, list, "餐馆套餐数据");
    }

    /**
     * 获取餐馆套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:respackage:query')")
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return success(resPackageService.selectResPackageByPackageId(packageId));
    }

    /**
     * 新增餐馆套餐
     */
    @PreAuthorize("@ss.hasPermi('system:respackage:add')")
    @Log(title = "餐馆套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResPackage resPackage)
    {
        return toAjax(resPackageService.insertResPackage(resPackage));
    }

    /**
     * 修改餐馆套餐
     */
    @PreAuthorize("@ss.hasPermi('system:respackage:edit')")
    @Log(title = "餐馆套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResPackage resPackage)
    {
        return toAjax(resPackageService.updateResPackage(resPackage));
    }

    /**
     * 删除餐馆套餐
     */
    @PreAuthorize("@ss.hasPermi('system:respackage:remove')")
    @Log(title = "餐馆套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(resPackageService.deleteResPackageByPackageIds(packageIds));
    }
}
